using AnimCollections;
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;

namespace DA.AnimGraph {
    public unsafe struct CurveBoard : IDisposable {
        private UnsafeHashMap<AUID, Curve> curves;
        public bool IsValid => curves.IsCreated;

        public CurveBoard(int capacity) {
            curves = new(capacity, Allocator.Persistent);
        }
        public CurveBoard(CurveBoard other) {
            curves = default;
            if (!other.IsValid) {
                return;
            }
            AnimNativeUtility.DeepCloneHashMap(out curves, other.curves, Allocator.Persistent);
        }

        public void Dispose() {
            curves.Dispose();
        }

        public void AddCurve(AUID uuid, Curve curve) {
            curves[uuid] = curve;
        }

        public bool GetCurve(AUID uuid, ref Curve value) {
            if (curves.TryGetValue(uuid, out value)) {
                return true;
            }
            return false;
        }
    }
}
